from selenium.webdriver.common.by import By
from framwork.pages.base_page import BasePage

"""
用例名称：仪表盘页面
"""


class DashBoardPage(BasePage):
    # 定位器
    url = "/crm/index.php"
    btn_dashboard_locator = (By.LINK_TEXT, "仪表盘")  # 仪表盘菜单
    btn_announcement_item_locator = (By.ID, 'show_announcement')  # 公告项
    btn_announcement_list_locator = (By.CLASS_NAME, 'dash-swtich')  # 公告列表
    btn_last_month_locator = (
        By.CSS_SELECTOR, '#calendar > div.c-grid > div.c-previous.c-grid-title.c-pad-top')  # 上一个月份
    btn_next_month_locator = (By.CSS_SELECTOR, '#calendar > div.c-grid > div.c-next.c-grid-title.c-pad-top')  # 下一个月份
    add_task_button_locator = (
        By.CSS_SELECTOR, "#calendar > div.c-event-grid > div.c-task-body > div.data-head > a")  # 添加任务
    success_announcement_item_locator = (By.CLASS_NAME, 'page-header')  # 公告列表项成功信息
    success_announcement_list_locator = (By.CSS_SELECTOR, 'body > div.container > div.page-header > h4')  # 公告列表成功信息
    success_next_last_month_locator = (By.XPATH, '//div[@class="c-month c-grid-title c-pad-top"]')  # 上下一个月的成功信息

    def click_dashboard_button(self):
        """点击仪表盘"""
        self.click(self.btn_dashboard_locator)

    def click_add_task_btn(self):
        """点击添加任务按钮"""
        self.click(self.add_task_button_locator)

    def click_announcement_item_button(self):
        """点击公告项"""
        self.click(self.btn_announcement_item_locator)

    def click_announcement_list_button(self):
        """点击公告列表"""
        self.click(self.btn_announcement_list_locator)

    def click_last_month_button(self):
        """点击上一个月"""
        self.click(self.btn_last_month_locator)

    def click_next_month_button(self):
        """点击下一个月"""
        self.click(self.btn_next_month_locator)

    def get_success_announcement_item_tips(self):
        """获取公告列表项成功信息"""
        return self.find_element(self.success_announcement_item_locator).text

    def get_success_announcement_list_tips(self):
        """获取公告列表成功信息"""
        return self.find_element(self.success_announcement_list_locator).text

    def get_success_next_last_month_tips(self):
        """获取切换月份成功信息"""
        return self.find_element(self.success_next_last_month_locator).text
